package com.bosssoft.exception;

import com.bosssoft.enums.DaoCode;
import com.bosssoft.enums.FibEnums;
import lombok.Getter;

/**
 * @author Aria
 */
@Getter
public class DaoException extends RuntimeException {
    private int code;
    private String msg;

    // 手动设置异常
    private DaoException(){

    }

    public static DaoException error(){
        DaoException daoException = new DaoException();
        daoException.setCodeAndMessage(DaoCode.TRANSACTIONAL_ERROR);
        return daoException;
    }

    public static DaoException error(FibEnums fibEnums){
        DaoException daoException = new DaoException();
        daoException.setCodeAndMessage(fibEnums);
        return daoException;
    }

    public  DaoException setCodeAndMessage(FibEnums fibEnums){
        this.code = fibEnums.getCode();
        this.msg = fibEnums.getMessage();
        return this;
    }
}
